package com.one.consumer.reserve.ui.activity;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.view.base.IListView;
import com.one.common.view.widget.MyTitleBar;
import com.one.consumer.BaseListActivityC;
import com.one.consumer.R;
import com.one.consumer.reserve.model.extra.CaseExtra;
import com.one.common.common.order.extra.ReserveExtra;
import com.one.consumer.reserve.model.item.CaseDetailItem;
import com.one.consumer.reserve.model.item.ProgramImageItem;
import com.one.consumer.reserve.presenter.DECaseDetailPresenter;
import com.one.consumer.reserve.ui.binder.CaseDetailBinder;

/**
 * author ：zhulunjun
 * email  ：zhulunjun@qq.com
 * date   ：2018/10/21 下午11:04
 * description ：案例详情
 **/
@Route(path = RouterPath.CASE_DETAIL)
public class CaseDetailActivity extends BaseListActivityC<DECaseDetailPresenter> implements IListView {
    private TextView tvBtnReserve;
    private LinearLayout llBtn;
    private ImageView ivLeft;
    private CaseExtra extra;

    @Override
    protected void initPresenter() {
        mPresenter = new DECaseDetailPresenter(this, this);
    }

    @Override
    public void registerDate() {
        register(ProgramImageItem.class, new CaseDetailBinder());
    }

    @Override
    public void loadData() {
        if (extra.getType().equals(ReserveExtra.STYLE_PR)) {
            mPresenter.getProgramImg();
        } else {
            mPresenter.getCaseDetail();
        }
    }

    @Override
    public void initView() {
        super.initView();
        hindLoadMore();
        hindRefresh();
        addBottomView(R.layout.include_btn_reserve);
        llBtn = successView.findViewById(R.id.ll_btn);
        tvBtnReserve = successView.findViewById(R.id.tv_btn);
        ivLeft = successView.findViewById(R.id.iv_icon);
        llBtn.setOnClickListener(this);
        if (extra.getType().equals(ReserveExtra.STYLE_PR)) {
            ivLeft.setVisibility(View.GONE);
            tvBtnReserve.setText("确定");
        }
    }

    @Override
    public void initData() {
        super.initData();
        loadData();
    }

    @Override
    protected void initTitle() {
        super.initTitle();
        extra = (CaseExtra) getIntent().getSerializableExtra(CaseExtra.getExtraName());
        if (extra != null) {
            getMyTitleBar().setMode(MyTitleBar.Mode.BACK_TITLE)
                    .setTitleText(extra.getCaseName() + "效果图");
        }
    }


    @Override
    public RecyclerView.LayoutManager getLayoutManager() {
        return new GridLayoutManager(this, 2);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v.getId() == R.id.ll_btn) {
            RouterManager.getInstance().go(RouterPath.ADD_RESERVE_DE,
                    new ReserveExtra(extra.getType(), extra.getCustomExtra()));
        }
    }
}
